<?php
/**
 * Cube PHP Framework
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * @author Dillen / Steffen
 */

namespace Library\Web;

/**
 * @class Library.Web.Sessions
 * 
 * Sessions class
 */
class Sessions extends \Library\ArrayObject
{
    private $_config;
    
	public function __construct()
	{
        $this->_config = \Library\Platform::getConfig()->sessions;
        
		if (!session_id() || !isset($_SESSION))
		{
            if (!isset($_COOKIE['CUBE_SESSID']))
            {
                session_regenerate_id(true);
            }
            
            session_cache_expire(60 * 24);
            session_cache_limiter('public');
            session_name('CUBE_SESSID');
			session_set_cookie_params(3600 * 24, $_SERVER['DOCUMENT_ROOT']);
			session_start();
			
			$this->_storage = $_SESSION;
		}
	}
	
	public function clear()
	{
		$this->_storage = array();
	}
	
	public function __destruct()
	{
		foreach($this->_storage as $key => $value)
		{
			$_SESSION[$key] = $value;
		}
	}
}